package com.mybook.app.controller;

import com.mybook.app.core.BaseResponse;
import com.mybook.app.request.BookInfoRequest;
import com.mybook.app.request.BookRequest;
import com.mybook.app.request.ShareListRequest;
import com.mybook.app.response.ShareDetail;
import com.mybook.app.service.ShareBookService;
import com.mybook.app.utils.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zjutsw on 2017/11/1.
 */
@RestController
@RequestMapping("/share")
public class ShareBookController {
    @Autowired
    private ShareBookService shareBookService;

    /**
     * 分享图书
     *
     * @param bookInfoRequest
     * @return
     */
    @PostMapping("book")
    public BaseResponse shareBook(@RequestBody BookInfoRequest bookInfoRequest) {
        Logger.debug(this, "分享图书");
        shareBookService.shareBook(bookInfoRequest);
        return BaseResponse.ok();
    }


    /**
     * 分享图书列表
     *
     * @param
     * @return
     */
    @PostMapping("list")
    public BaseResponse shareList(@RequestBody ShareListRequest shareListRequest) {
        Logger.debug(this, "我的分享图书");
        return shareBookService.shareList(shareListRequest);
    }

    /**
     * 分享图书详情
     *
     * @param
     * @return
     */
    @PostMapping("detail")
    public BaseResponse shareDetail(@RequestBody BookRequest bookRequest) {
        Logger.debug(this, "分享图书详情");
        ShareDetail shareDetail = shareBookService.shareDetail(bookRequest.getbId());
        return new BaseResponse(shareDetail);
    }

    /**
     * 分享图书详情
     *
     * @param
     * @return
     */
    @PostMapping("back")
    public BaseResponse shareBack(@RequestBody BookRequest bookRequest) {
        Logger.debug(this, "分享图书详情");
        shareBookService.shareBack(bookRequest.getbId());
        return BaseResponse.ok();
    }
}
